lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

Declarations, definitions, init.md (805B)


      1 +++
      2 title = 'Declarations, definitions, init'
      3 +++
      4 # Declarations, definitions, init
      5 Each definition is a declaration, but not each declaration is also a definition.
      6 
      7 ## Declarations
      8 - a declaration is a statement that introduces a name into a scope
      9 - declare variables/functions before use
     10 - declarations say how something can be used, not how it’s implemented
     11 - in function declaration, named parameters are not necessary, but useful
     12 
     13 ## Definitions
     14 - a definition fully specifies the entity declared
     15 - sets aside memory for the variable
     16 
     17 ## Initialisation
     18 ways of initialising:
     19 
     20 - = syntax — `double d = 2;`
     21 - () syntax — `vector<int> v(10);`
     22     - specifies number of elements
     23 - {} syntax — `vector<int> v{1,2,3};`
     24     - gives a “vector literal"
     25 
     26 with const, initialisation is mandatory